package com.mjk.common.ai.work.admin;

import com.mjk.common.ai.dto.UserAddReq;
import com.mjk.common.ai.dto.UserEditReq;
import com.mjk.common.ai.dto.UserInfoDto;
import com.mjk.common.ai.dto.UserSearchReq;
import com.mjk.common.ai.entity.User;
import com.mjk.common.ai.service.UserService;
import com.mjk.common.base.error.BeeError;
import com.mjk.common.base.response.BeeResponse;
import com.mjk.common.base.work.BaseWork;
import com.mjk.common.base.work.annotation.BeeWork;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;

@BeeWork(work = "user")
public class AdminUserWork extends BaseWork {
    @Resource
    private UserService userService;

    public BeeResponse getUserList(UserSearchReq userSearchReq) {
        return BeeError.BEE_SUC.tranceError(
                userService.search(userSearchReq, userSearchReq.getPageStart(), userSearchReq.getPageSize())
        );
    }

    public BeeResponse getUserInfo(UserSearchReq userSearchReq) {
        User user = userService.getByUuidOrThrow(userSearchReq.getUuid());
        UserInfoDto result = new UserInfoDto();
        BeanUtils.copyProperties(user, result);
        return BeeError.BEE_SUC.tranceError(result);
    }

    public BeeResponse addUser(UserAddReq addUserReq) {
        userService.addUser(addUserReq);
        return BeeError.BEE_SUC.tranceError();
    }

    public BeeResponse activeByUuid(UserSearchReq addUserReq) {
        userService.activeByUuid(addUserReq.getUuid());
        return BeeError.BEE_SUC.tranceError();
    }

    public BeeResponse freezeByUuid(UserSearchReq addUserReq) {
        userService.freeze(addUserReq.getUuid());
        return BeeError.BEE_SUC.tranceError();
    }

    public BeeResponse editUser(UserEditReq userEditReq) {
        userService.editUser(userEditReq);
        return BeeError.BEE_SUC.tranceError();
    }
}
